import MySQLdb,datetime
cxn=MySQLdb.connect(db='pachong',host='localhost',user='root',passwd='123456ms')
cur=cxn.cursor()

sql='select min(id),max(id) from csdn'
cur.execute(sql)
min_id,max_id=cur.fetchone()
print min_id,max_id

step=10**5
idx=min_id
record_num=0

while idx<=max_id:
    sql_pref='select * from %s'%'csdn'
    sql=sql_pref+' where id between %s and %s'
    cur.execute(sql,(str(idx),str(idx+step)))
    for record in cur.fetchall():
        last_update_time=record[2]
        print record
        time_format='%Y-%m-%d %H:%M:%S'
        ldt=datetime.datetime.strptime(last_update_time,time_format)
        now=datetime.datetime.now()
        if (now-ldt).days>1:
            print (now-ldt).days
            sql='delete from csdn where id=%s'
            cur.execute(sql,str(record[0]))
        record_num+=1
    idx+=step
print record_num

cxn.commit()

cur.close()

cxn.close()
